package com.government.web.controller.tag;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.government.common.core.domain.entity.SysDept;
import com.government.tag.vo.TagTypeVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.government.common.annotation.Log;
import com.government.common.core.controller.BaseController;
import com.government.common.core.domain.AjaxResult;
import com.government.common.enums.BusinessType;
import com.government.tag.domain.TagType;
import com.government.tag.service.ITagTypeService;
import com.government.common.utils.poi.ExcelUtil;
import com.government.common.core.page.TableDataInfo;

/**
 * 标签类型Controller
 * 
 * @author system
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/tag/type")
public class TagTypeController extends BaseController
{
    @Autowired
    private ITagTypeService tagTypeService;

    /**
     * 查询标签类型列表
     */
    @PreAuthorize("@ss.hasPermi('tag:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(TagType tagType)
    {
        startPage();
        List<TagTypeVO> list = tagTypeService.selectTagTypeList(tagType);
        return getDataTable(list);
    }

    /**
     * 导出标签类型列表
     */
    @PreAuthorize("@ss.hasPermi('tag:type:export')")
    @Log(title = "标签类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TagType tagType)
    {
        List<TagTypeVO> list = tagTypeService.selectTagTypeList(tagType);
        ExcelUtil<TagTypeVO> util = new ExcelUtil<TagTypeVO>(TagTypeVO.class);
        util.exportExcel(response, list, "标签类型数据");
    }

    /**
     * 获取标签类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('tag:type:query')")
    @GetMapping(value = "/{tagTypeId}")
    public AjaxResult getInfo(@PathVariable("tagTypeId") Long tagTypeId)
    {
        return success(tagTypeService.selectTagTypeByTagTypeId(tagTypeId));
    }

    /**
     * 新增标签类型
     */
    @PreAuthorize("@ss.hasPermi('tag:type:add')")
    @Log(title = "标签类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TagType tagType)
    {
        return toAjax(tagTypeService.insertTagType(tagType));
    }

    /**
     * 修改标签类型
     */
    @PreAuthorize("@ss.hasPermi('tag:type:edit')")
    @Log(title = "标签类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TagType tagType)
    {
        return toAjax(tagTypeService.updateTagType(tagType));
    }

    /**
     * 删除标签类型
     */
    @PreAuthorize("@ss.hasPermi('tag:type:remove')")
    @Log(title = "标签类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagTypeIds}")
    public AjaxResult remove(@PathVariable Long[] tagTypeIds)
    {
        return toAjax(tagTypeService.deleteTagTypeByTagTypeIds(tagTypeIds));
    }

    /**
     * 查询一级标签类型下拉列表
     */
    @GetMapping("/selectFirstTagTypeList")
    public TableDataInfo selectFirstTagTypeList()
    {
        List<TagType> list = tagTypeService.selectFirstTagTypeList();
        return getDataTable(list);
    }

    /**
     * 获取标签类型树列表
     */
    @GetMapping("/tagTypeTree")
    public AjaxResult tagTypeTree()
    {
        return success(tagTypeService.selectTagTypeTreeList());
    }
}
